import { createApp } from "vue";
import App from "./App.vue";
import router from "./router";
import "element-plus/dist/index.css";


import ElementPlus from "element-plus"; //全局引入
import { useAuth } from "./common/useAuth";

const app = createApp(App);

app.use(ElementPlus);
app.use(router);

app.mount('#app');

const { token, loadUser } = useAuth();
if (token.value) {
    loadUser().catch(() => {
        // ignore, user will be redirected to login by guards if needed
    });
}
router.beforeEach((to, from, next) => {
    if (to.meta.requiresAuth && !token.value) {
        next({ name: 'login', query: { next: to.fullPath } });
    } else next();
});


